language = "VBScript"
interface = "1.0"

crt.Screen.Synchronous = True

'设备名称
sysname = "F2_AGG"
'设备IP地址
'admin_ip="192.168.99.123"
'admin_user="zmrbak"
'admin_pass="admin"
'snmp_read_pass="admin"
vlan_id = Array(160, 110, 120, 38, 39)
dhcp_select_interface  = Array(160)
distinct_vlan_ip_last = "2"
dhcp_server_dns  =  Array("192.168.100.5", "192.168.170.1")
interface_port = Array("g", "a","38" ,2, 2)


'----------------------------------------- 服务项目是否开启---------------------------------------
DHCP_SERVER_Enabled = 1
'--------------------------------- 积累vlan_id的所有元素到函数sendString中-------------------------
Dim sendString
sendString = ""
vlan_idddd = vlan_id
For i = LBound(vlan_idddd) To UBound(vlan_idddd)
    sendString = sendString & CStr(vlan_idddd(i)) & " "
Next
'-------------------------------积累dhcp_server_dns的所有元素到函数sendABC中----------------------------------
Dim sendABC
sendABC = ""
DDHHCCP = dhcp_server_dns
For k = LBound(DDHHCCP) To UBound(DDHHCCP)
    sendABC = sendABC & CStr(DDHHCCP(k)) & " "
Next
'-------------------------------------- Set_Host------------------------------

'-------------------------------------- Set_Host------------------------------
Sub Set_Host
 	crt.Screen.Send "sys"& chr(13)

	crt.Screen.Send "sysname "& sysname & chr(13)          '修改系统名称
	crt.Screen.WaitForString sysname
	crt.Screen.Send "undo info-center enable" & chr(13)     '关闭系统提示
	crt.Screen.WaitForString sysname
	crt.Screen.Send "vlan  batch  "& sendString & chr(13)      '创建vlan
	crt.Screen.WaitForString sysname
	'--------------------------------------
	if DHCP_SERVER_Enabled = 1 then                            'DHCP服务开启
		crt.Screen.Send "dhcp enable" & chr(13)
		crt.Screen.WaitForString sysname
	end if
	'--------------------------------------
End Sub
'-----------------------------------------------------------------------------------
Sub Set_vlanif
	For s = LBound(vlan_id) To UBound(vlan_id)
		crt.Screen.Send "interface vlanif  "& vlan_id(s) & chr(13)
		crt.Screen.WaitForString vlan_id(s)
		For j = LBound(dhcp_select_interface) To UBound(dhcp_select_interface)
	        If vlan_id(s) <> dhcp_select_interface(j) Then
        		crt.Screen.Send "ip add 192.168."& vlan_id(s) & ".1 255.255.255.0" & chr(13)
        		crt.Screen.WaitForString vlan_id(s)
            	crt.Screen.Send "dhcp select interface " & chr(13)
				crt.Screen.WaitForString vlan_id(s)
				crt.Screen.Send "dhcp server dns-list  " & sendABC & chr(13)
				crt.Screen.WaitForString vlan_id(s)
			ElseIf vlan_id(s) = dhcp_select_interface(j) Then
        		crt.Screen.Send "ip add 192.168."& vlan_id(s) &"." & distinct_vlan_ip_last & "  255.255.255.0" & chr(13)
        		crt.Screen.WaitForString vlan_id(s)
			End If
		Next
	    crt.Screen.Send "quit" & chr(13)
		crt.Screen.WaitForString sysname
	Next
End Sub
'------------------------------------------------------------------------------------------------------------------
Sub my_interface_port( nettype, link_type, vports, start_port, end_port )
	ports=start_port
	Do
		if ports<=end_port then
			crt.Screen.Send "interface "&nettype&"0/0/"&ports & chr(13)
			crt.Screen.WaitForString sysname
              If link_type = "a" Then
                crt.Screen.Send "port link-type access" & chr(13)
		        crt.Screen.WaitForString sysname
	            crt.Screen.Send "port default vlan "& vports & chr(13)
		        crt.Screen.WaitForString sysname
              Elseif link_type = "t" Then
				crt.Screen.Send "port link-type trunk" & chr(13)
		    	crt.Screen.WaitForString sysname
	        	crt.Screen.Send "port trunk allow-pass vlan  "& vports  & chr(13)
	        	crt.Screen.WaitForString sysname
			  end if
			ports=ports+1
		else
			crt.Screen.Send "q"& chr(13)
			exit do
		end if
	Loop
End Sub

'---------------------------------------------------------------------------------------
Sub Main
	Call Set_Host
 	Call Set_vlanif
	Call my_interface_port(interface_port(0),interface_port(1),interface_port(2),interface_port(3),interface_port(4))
End Sub


